//
//  WhsInAddView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/30.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "WhsInAddView.h"

#import "GoodsView.h"

@interface WhsInAddView()<UITextViewDelegate,UITextFieldDelegate>
@end

@implementation WhsInAddView
{
    GoodsView*GoodView;
    UILabel * label;
    UIImageView*imagess;
    UIView* myToolBar;

}
@synthesize mDelegate;


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       }

    return self;
}
-(void)setModel:(WhsInAddModel *)model{

    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    
    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300/2-10)];
    view.backgroundColor=zuiqianhuiColor;
    view.layer.borderWidth = 0.35;
    view.layer.borderColor = qianhuiColor.CGColor;
    [self addSubview:view];
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 88/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [view addSubview:view1];
    UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth, 0.35)];
    line1.backgroundColor=qianhuiColor;
    [view addSubview:line1];
    UILabel* userName=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 40, 88/2)];
    userName.text=[NSString stringWithFormat:@"员工"];
    userName.textColor=zhonghuiColor;
    userName.font=[UIFont systemFontOfSize:15];
    [view addSubview:userName];
    
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString* UserName = [user1 objectForKey:@"userName"];
    //  self.GuideCode = [user1 objectForKey:@"UserCode"];
    UIButton*userNameBtn=[[UIButton alloc]initWithFrame:CGRectMake(50, 0,ScreenWidth-100,88/2)];
    [userNameBtn setTitle:UserName forState:UIControlStateNormal];
    userNameBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    userNameBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [userNameBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view addSubview:userNameBtn];
    
    
    UIView*view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 175/2)];
    view2.backgroundColor=[UIColor whiteColor];
    view2.layer.borderWidth = 0.35;
    view2.layer.borderColor = qianhuiColor.CGColor;
    [view addSubview:view2];
    
    UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(15,  175/2/2, ScreenWidth-30, 0.35)];
    line3.backgroundColor=qianhuiColor;
    [view2 addSubview:line3];
    
    UILabel*typeLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0, 200, 175/2/2)];
    typeLabel.text=@"类型";
    typeLabel.textColor=zhonghuiColor;
    typeLabel.font=[UIFont systemFontOfSize:contenfot];
    [view2 addSubview:typeLabel];
    _typeBtn=[[UIButton alloc]initWithFrame:CGRectMake(50,  0, ScreenWidth-100,175/2/2)];
    _typeBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    _typeBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [_typeBtn addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [_typeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:_typeBtn];
    
    UIButton*jiantouBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,15,8, 13)];
    [jiantouBtn setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [jiantouBtn addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:jiantouBtn];
    
    
    UILabel*whsLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,175/2/2, 200, 175/2/2)];
    whsLabel.text=@"仓库";
    whsLabel.textColor=zhonghuiColor;
    whsLabel.font=[UIFont systemFontOfSize:contenfot];
    [view2 addSubview:whsLabel];
    
    _whsBtn=[[UIButton alloc]initWithFrame:CGRectMake(50,  175/2/2, ScreenWidth-100,175/2/2)];
    [_whsBtn setTitle:@"                                                             " forState:UIControlStateNormal];
    _whsBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    _whsBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [_whsBtn addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
    [_whsBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view2 addSubview:_whsBtn];
    
    UIButton*jiantouBtn1 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-30,175/2/2+15,8, 13)];
    [jiantouBtn1 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    [jiantouBtn1 addTarget:self action:@selector(xuanzhidaogou1:) forControlEvents:UIControlEventTouchUpInside];
    [view2 addSubview:jiantouBtn1];
    
    
    
    UIView*view3=[[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+ 10, ScreenWidth, 45)];
    view3.backgroundColor=[UIColor whiteColor];
    [self addSubview:view3];
    UILabel *lineL=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.35)];
    lineL.backgroundColor=qianhuiColor;
    [view3 addSubview:lineL];
    
    UILabel*GoodsLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 45)];
    GoodsLabel.text=@"商品信息";
    GoodsLabel.textColor=[UIColor blackColor];
    GoodsLabel.font=[UIFont systemFontOfSize:15];
    [view3 addSubview:GoodsLabel];
    UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
    lineLabel1.backgroundColor=qianhuiColor;
    [view3 addSubview:lineLabel1];
    
    
    for (int i = 0; i<self.itemNameArray.count; i++) {
        
        GoodView = [[GoodsView alloc]initWithFrame:CGRectMake(0, view3.bottom+(120*i), ScreenWidth, 120)];
        GoodView.backgroundColor=[UIColor whiteColor];
        [GoodView.headImageFull setImageWithURL:[self.headImageFullArray objectAtIndex:i]  placeholderImage:[UIImage imageNamed:@""]];
        [GoodView.headImageFull.layer setCornerRadius:6.0];
        [GoodView.headImageFull.layer setBorderWidth:0.3];
        [GoodView.headImageFull.layer setMasksToBounds:YES];
        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
        [GoodView.headImageFull.layer setBorderColor:colorref2];//边框颜色
        
        GoodView.itemName.text=[NSString stringWithFormat:@"%@%@",[self.itemCodeArray objectAtIndex:i],[self.itemNameArray objectAtIndex:i]];
        
        GoodView.quantity.text=[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]];
        
        NSMutableAttributedString *AttributedStr1 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"数量 %@",[self.quantityArray objectAtIndex:i]]];
        
        [AttributedStr1 addAttribute:NSFontAttributeName
         
                               value:[UIFont systemFontOfSize:contenfot]
         
                               range:NSMakeRange(0, 3)];
        
        [AttributedStr1 addAttribute:NSForegroundColorAttributeName
         
                               value:zhonghuiColor
         
                               range:NSMakeRange(0, 3)];
        
        
        GoodView.quantity.attributedText = AttributedStr1;
        
        
        NSNumber*Total =[self.dealPriceArray objectAtIndex:i];
        
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
        GoodView.dealPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
        GoodView.dealPrice.textColor=hongseColor;
        
        
        NSMutableAttributedString *AttributedStr11 = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@",formattedNumberString]];
        
        [AttributedStr11 addAttribute:NSFontAttributeName
         
                                value:[UIFont systemFontOfSize:contenfot]
         
                                range:NSMakeRange(0, 1)];
        
        [AttributedStr11 addAttribute:NSForegroundColorAttributeName
         
                                value:hongseColor
         
                                range:NSMakeRange(0, 1)];
        
        
        GoodView.dealPrice.attributedText = AttributedStr11;
        GoodView.itemType.text=[NSString stringWithFormat:@"%@",[self.specNameArray objectAtIndex:i]];
        if (i==self.specNameArray.count-1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
            lineLabel1.backgroundColor=qianhuiColor;
            [GoodView addSubview:lineLabel1];
        }else{
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
            lineLabel1.backgroundColor=qianhuiColor;
            [GoodView addSubview:lineLabel1];
            
            
        }
        
        [self addSubview:GoodView];
    }

    UIView*view6=[[UIView alloc]initWithFrame:CGRectMake(0, GoodView.bottom+10, ScreenWidth, 100)];
    view6.backgroundColor=[UIColor whiteColor];
    view6.layer.borderWidth = 0.35;
    view6.layer.borderColor = qianhuiColor.CGColor;
    [self addSubview:view6];
    
    _remark=[[UITextView alloc]init];
    _remark.frame=CGRectMake(20, 10, ScreenWidth-40, 90);
    _remark.backgroundColor = [UIColor whiteColor];//设置它的背景颜色/Users/jiezsoft/Desktop/
    _remark.scrollEnabled = YES;//是否可以拖动
    _remark.delegate=self;
    _remark.font = [UIFont fontWithName:@"Arial" size:15.0];//设置字体名字和字体大小
    _remark.layer.borderWidth =0.0;
    CGColorSpaceRef registedSpace11 = CGColorSpaceCreateDeviceRGB();
    CGColorRef tureBTncolorref111 = CGColorCreate(registedSpace11,(CGFloat[]){ 0, 0, 0, 0.3 });
    //tv.keyboardType = UIKeyboardTypePhonePad;
    [_remark.layer setBorderColor:tureBTncolorref111];//边框颜色
    _remark.layer.cornerRadius =0;
    [view6 addSubview:_remark];
    imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
    imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
    [_remark addSubview:imagess];
    label=[[UILabel alloc]init];
    label.frame =CGRectMake(23, 7, ScreenWidth-60, 14);
    label.text = @"备注";
    label.textColor=zuiqianhuiColor;
    label.numberOfLines=0;
    label.font=[UIFont systemFontOfSize:14];
    label.enabled = NO;//lable必须设置为不可用
    label.backgroundColor = [UIColor clearColor];
    [_remark addSubview:label];
    
    _remark.inputAccessoryView = myToolBar;
    _heightView=[[UIView alloc]init];
    _heightView.backgroundColor=qianhuiColor;
    [self addSubview:_heightView];
    _heightView.frame=CGRectMake(0, view6.bottom, ScreenWidth, 0.15);

}


-(void)xuanzhidaogou:(UIButton *)sender{
 [mDelegate type:@""];
}
-(void)xuanzhidaogou1:(UIButton *)sender{
 [mDelegate whs:@""];

}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
  [mDelegate BeginEditing:@""];

    return self;
}

-(void)textViewDidChange:(UITextView *)textView
{
     if (textView.text.length == 0) {
        [imagess removeFromSuperview];
        imagess=[[UIImageView alloc]initWithFrame:CGRectMake(0, 5, 20, 16)];
        imagess.image=[UIImage imageNamed:@"_0000_xingxifankui.png"];
        [_remark addSubview:imagess];
        label.text = @"备注";

    }else{
        [imagess removeFromSuperview];
        label.text = @"";
    }
}
//回收键盘
-(void)OnTapDone{
    [_remark resignFirstResponder];
      [mDelegate OnTapDone:@""];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//    MYmainScroll .frame =CGRectMake(0,100, ScreenWidth, ScreenHeight-300/2);
//    [UIView commitAnimations];

}

-(void)store{
    
  
    
}
-(void)certificationBtn:(UIButton*)sender{
    
  
}
@end
